<!--

    Copyright (C) 2015 The Gravitee team (http://gravitee.io)

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

            http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

-->
<h2 mat-dialog-title>Generate a token</h2>

<form autocomplete="off" [formGroup]="tokenForm" (ngSubmit)="onSubmit()">
  <mat-dialog-content>
    <div *ngIf="!hasBeenGenerated" class="form">
      <mat-form-field appearance="fill">
        <mat-label>Name</mat-label>
        <input matInput formControlName="name" required />
        <mat-hint align="end">{{ tokenForm.get('name').value?.length ?? 0 }}/64</mat-hint>
        <mat-hint>What's this token for?</mat-hint>
        <mat-error *ngIf="tokenForm.get('name').hasError('maxlength')">Name has to be less than 64 characters long.</mat-error>
        <mat-error *ngIf="tokenForm.get('name').hasError('minlength')">Name has to be greater than 2 characters long.</mat-error>
        <mat-error *ngIf="tokenForm.get('name').hasError('required')">Name is required.</mat-error>
      </mat-form-field>
    </div>

    <div class="content" *ngIf="hasBeenGenerated">
      <gio-banner-info class="content__banner">
        Make sure to copy your new personal access token now. You won’t be able to see it again.
      </gio-banner-info>
      <h4>Token</h4>
      <div class="content__code__token" gioClipboardCopyWrapper [contentToCopy]="token.token" [alwaysVisible]="true">
        <code>{{ token.token }}</code>
      </div>
      <h4>Usage</h4>
      <div class="content__code" gioClipboardCopyWrapper [contentToCopy]="getExampleOfUse(token.token)" [alwaysVisible]="true">
        <code>{{ getExampleOfUse(token.token) }}</code>
      </div>
    </div>
  </mat-dialog-content>

  <mat-dialog-actions class="actions">
    <button mat-button [mat-dialog-close]="false">{{ hasBeenGenerated ? 'Close' : 'Cancel' }}</button>
    <button mat-button color="primary" *ngIf="!hasBeenGenerated" [disabled]="tokenForm.invalid" type="submit">Generate</button>
  </mat-dialog-actions>
</form>
